<?php
class Ialbum_Installer extends Engine_Package_Installer_Module
{
  function onPreinstall() {
  	$db = $this->getDb();
    $select = new Zend_Db_Select($db);
    $select->from('engine4_core_modules')
            ->where('name = ?', 'album')
            ->limit(1);
    $row = $select->query()->fetch();
   if(empty($row)){
      $base_url = Zend_Controller_Front::getInstance()->getBaseUrl();
      return $this->_error("<span style='color:red'>You have not installed the Album Plugin on your site. Please first install Album Plugin on your site and then install this Plugin.</span><br/> <a href='" . $base_url . "/manage'>Click here</a> to go to Manage Packages.");
   }else{
   	parent::onPreinstall();
   }
  }
 public function onInstall()
  {  	
	    $this->_albumPhotoViewPage();
	    $this->_albumViewPage();
	    $this->_albumBrowsePage();
	    $this->_userProfileAlbums();
	  	$this->_albumShowPage();
	  	$this->_albumHomePage();
	  	$this->update();
	    parent::onInstall();
  }
 protected function _albumViewPage()
  {
    $db = $this->getDb();

    // profile page
    $page_id = $db->select()
      ->from('engine4_core_pages', 'page_id')
      ->where('name = ?', 'ialbum_album_view')
      ->limit(1)
      ->query()
      ->fetchColumn();
      
    if (!$page_id) {
      // Insert page
      $db->insert('engine4_core_pages', array(
        'name' => 'ialbum_album_view',
        'displayname' => 'iAlbum - Album View Page',
        'title' => 'iAlbum - Album View Page',
        'description' => 'This page displays an adv.album\'s photos.',
        'provides' => 'subject=album',
        'custom' => 0,
      ));
      $page_id = $db->lastInsertId();
      
	 // Insert top
      $db->insert('engine4_core_content', array(
        'type' => 'container',
        'name' => 'top',
        'page_id' => $page_id,
        'order' => 1,
      ));
      $top_id = $db->lastInsertId();
      
     // Insert main
      $db->insert('engine4_core_content', array(
        'type' => 'container',
        'name' => 'main',
        'page_id' => $page_id,
      	'order' => 2,
      ));
      $main_id = $db->lastInsertId();

      // Insert top-middle
      $db->insert('engine4_core_content', array(
        'type' => 'container',
        'name' => 'middle',
        'page_id' => $page_id,
        'parent_content_id' => $top_id,
      ));
      $top_middle_id = $db->lastInsertId();
      
      // Insert main-middle
      $db->insert('engine4_core_content', array(
        'type' => 'container',
        'name' => 'middle',
        'page_id' => $page_id,
        'parent_content_id' => $main_id,
        'order' => 2,
      ));
      $main_middle_id = $db->lastInsertId();
		
      // Insert main-right
      $db->insert('engine4_core_content', array(
        'type' => 'container',
        'name' => 'right',
        'page_id' => $page_id,
        'parent_content_id' => $main_id,
        'order' => 1,
      ));
      $main_right_id = $db->lastInsertId();
      
      // Insert Album Navigation
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'ialbum.album-navigation',
        'page_id' => $page_id,
        'parent_content_id' => $top_middle_id,
        'order' => 1,
      ));
      
      // for main col
      // Insert content
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'core.content',
        'page_id' => $page_id,
        'parent_content_id' => $main_middle_id,
        'order' => 1,
      ));
      // Insert Comment
      	$db->insert('engine4_core_content', array(
	        'type' => 'widget',
	        'name' => 'ialbum.comment',
	        'page_id' => $page_id,
	        'parent_content_id' => $main_middle_id,
	        'order' => 2,
        ));
      // for right col
      //Insert People In Album
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'ialbum.people-in-album',
        'page_id' => $page_id,
        'parent_content_id' => $main_right_id,
        'order' => 1,
      	'params' => '{"title":"People In This Album"}',
      ));
      //Insert List Other Albums
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'ialbum.list-other-albums',
        'page_id' => $page_id,
        'parent_content_id' => $main_right_id,
        'order' => 2,
      	'params' => '{"title":"%s\'s Other Albums"}',
      ));
      //Insert Friend Photos Tagged
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'ialbum.friend-photos-tagged',
        'page_id' => $page_id,
        'parent_content_id' => $main_right_id,
        'order' => 3,
      	'params' => '{"title":"Friend\'s Photos Tagged"}',
      ));
      //Insert Friend Photos
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'ialbum.friend-photos',
        'page_id' => $page_id,
        'parent_content_id' => $main_right_id,
        'order' => 4,
      	'params' => '{"title":"Friend\'s Photos"}',
      ));
    }
      
    return $this;
  }
protected function _albumPhotoViewPage()
  {
    $db = $this->getDb();

    // profile page
    $page_id = $db->select()
      ->from('engine4_core_pages', 'page_id')
      ->where('name = ?', 'ialbum_photo_view')
      ->limit(1)
      ->query()
      ->fetchColumn();
      
    if (!$page_id) {
      // Insert page
      $db->insert('engine4_core_pages', array(
        'name' => 'ialbum_photo_view',
        'displayname' => 'iAlbum - Album Photo View Page',
        'title' => 'iAlbum - Album Photo View Page',
        'description' => 'This page displays an adv.album\'s photo.',
        'provides' => 'subject=album_photo',
        'custom' => 0,
      ));
      $page_id = $db->lastInsertId();
      
     // Insert main
      $db->insert('engine4_core_content', array(
        'type' => 'container',
        'name' => 'main',
        'page_id' => $page_id,
      ));
      $main_id = $db->lastInsertId();

      // Insert main-middle
      $db->insert('engine4_core_content', array(
        'type' => 'container',
        'name' => 'middle',
        'page_id' => $page_id,
        'parent_content_id' => $main_id,
        'order' => 2,
      ));
      $main_middle_id = $db->lastInsertId();
      
	  // Insert main-right
      $db->insert('engine4_core_content', array(
        'type' => 'container',
        'name' => 'right',
        'page_id' => $page_id,
        'parent_content_id' => $main_id,
        'order' => 1,
      ));
      $main_right_id = $db->lastInsertId();
      
      // main-middle
      // Insert content
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'core.content',
        'page_id' => $page_id,
        'parent_content_id' => $main_middle_id,
        'order' => 1,
      ));
      //  main right
      // Insert ialbum.photos-in-album
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'ialbum.photos-in-album',
        'page_id' => $page_id,
        'parent_content_id' => $main_right_id,
        'order' => 1,
      	'params' => '{"title":"Photos In Album"}',      
      ));
      // Insert ialbum.friend-photos
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'ialbum.friend-photos',
        'page_id' => $page_id,
        'parent_content_id' => $main_right_id,
        'order' => 2,
      	'params' => '{"title":"Friends\' Photos"}',      
      ));
      // Insert ialbum.friend-photos
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'ialbum.friend-photos-tagged',
        'page_id' => $page_id,
        'parent_content_id' => $main_right_id,
        'order' => 3,
      	'params' => '{"title":"Friends\' Photos Tagged"}',
      ));
    }
    
    return $this;
  }
  
protected function _albumBrowsePage()
  {
    
    $db = $this->getDb();

    // profile page
    $page_id = $db->select()
      ->from('engine4_core_pages', 'page_id')
      ->where('name = ?', 'ialbum_index_browse')
      ->limit(1)
      ->query()
      ->fetchColumn();

    
    // insert if it doesn't exist yet
    if( !$page_id ) {
      // Insert page
      $db->insert('engine4_core_pages', array(
        'name' => 'ialbum_index_browse',
        'displayname' => 'iAlbum - Album Browse Page',
        'title' => 'iAlbum - Album Browse Page',
        'description' => 'This page lists adv.album entries.',
        'custom' => 0,
      ));
      $page_id = $db->lastInsertId();
      
      // Insert top
      $db->insert('engine4_core_content', array(
        'type' => 'container',
        'name' => 'top',
        'page_id' => $page_id,
        'order' => 1,
      ));
      $top_id = $db->lastInsertId();
      
      // Insert main
      $db->insert('engine4_core_content', array(
        'type' => 'container',
        'name' => 'main',
        'page_id' => $page_id,
        'order' => 2,
      ));
      $main_id = $db->lastInsertId();
      
      // Insert top-middle
      $db->insert('engine4_core_content', array(
        'type' => 'container',
        'name' => 'middle',
        'page_id' => $page_id,
        'parent_content_id' => $top_id,
      ));
      $top_middle_id = $db->lastInsertId();
      
      // Insert main-middle
      $db->insert('engine4_core_content', array(
        'type' => 'container',
        'name' => 'middle',
        'page_id' => $page_id,
        'parent_content_id' => $main_id,
        'order' => 2,
      ));
      $main_middle_id = $db->lastInsertId();
      
      // Insert main-right
      $db->insert('engine4_core_content', array(
        'type' => 'container',
        'name' => 'right',
        'page_id' => $page_id,
        'parent_content_id' => $main_id,
        'order' => 1,
      ));
      $main_right_id = $db->lastInsertId();
      
      // Insert menu
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'ialbum.browse-menu',
        'page_id' => $page_id,
        'parent_content_id' => $top_middle_id,
        'order' => 1,
      ));
      
      // Insert content
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'core.content',
        'page_id' => $page_id,
        'parent_content_id' => $main_middle_id,
        'order' => 1,
      ));
      
      // Insert search
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'ialbum.browse-search',
        'page_id' => $page_id,
        'parent_content_id' => $main_right_id,
        'order' => 1,
      ));
      
      // Insert browse menu
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'ialbum.browse-menu-quick',
        'page_id' => $page_id,
        'parent_content_id' => $main_right_id,
        'order' => 2,
      ));
      
      // Insert ialbum.album-categories
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'ialbum.album-categories',
        'page_id' => $page_id,
        'parent_content_id' => $main_right_id,
        'order' => 3,
      	'params' => '{"title":"Album Categories"}',
      ));
       // Insert ialbum.top-poster
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'ialbum.top-poster',
        'page_id' => $page_id,
        'parent_content_id' => $main_right_id,
        'order' => 4,
      	'params' => '{"title":"Top Poster"}',
      ));      
    }
    
    return $this;
  }
  
  protected function _albumShowPage()
  {
    
    $db = $this->getDb();

    // profile page
    $page_id = $db->select()
      ->from('engine4_core_pages', 'page_id')
      ->where('name = ?', 'ialbum_index_show')
      ->limit(1)
      ->query()
      ->fetchColumn();

    
    // insert if it doesn't exist yet
    if( !$page_id ) {
      // Insert page
      $db->insert('engine4_core_pages', array(
        'name' => 'ialbum_index_show',
        'displayname' => 'iAlbum - Show Photos',
        'title' => 'iAlbum - Show Photos',
        'description' => 'This page show albums and photos tagged of users.',
        'custom' => 0,
      ));
      $page_id = $db->lastInsertId();
      
      // Insert top
      $db->insert('engine4_core_content', array(
        'type' => 'container',
        'name' => 'top',
        'page_id' => $page_id,
        'order' => 1,
      ));
      $top_id = $db->lastInsertId();
      
      // Insert main
      $db->insert('engine4_core_content', array(
        'type' => 'container',
        'name' => 'main',
        'page_id' => $page_id,
        'order' => 2,
      ));
      $main_id = $db->lastInsertId();
      
      // Insert top-middle
      $db->insert('engine4_core_content', array(
        'type' => 'container',
        'name' => 'middle',
        'page_id' => $page_id,
        'parent_content_id' => $top_id,
      ));
      $top_middle_id = $db->lastInsertId();
      
      // Insert main-middle
      $db->insert('engine4_core_content', array(
        'type' => 'container',
        'name' => 'middle',
        'page_id' => $page_id,
        'parent_content_id' => $main_id,
        'order' => 2,
      ));
      $main_middle_id = $db->lastInsertId();
      
      // Insert menu
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'ialbum.browse-menu',
        'page_id' => $page_id,
        'parent_content_id' => $top_middle_id,
        'order' => 1,
      ));
      //main middle
      // Insert content
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'core.content',
        'page_id' => $page_id,
        'parent_content_id' => $main_middle_id,
        'order' => 1,
      ));
	  
      // Insert ialbum.albums-of-users
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'ialbum.albums-of-users',
        'page_id' => $page_id,
        'parent_content_id' => $main_middle_id,
        'order' => 2,
      ));
      
      // Insert ialbum.photos-of-users
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'ialbum.photos-of-users',
        'page_id' => $page_id,
        'parent_content_id' => $main_middle_id,
        'order' => 3,
      ));
    }
    
    return $this;
  }
  
  protected function _userProfileAlbums()
  {
    //
    // install content areas
    //
    $db     = $this->getDb();
    $select = new Zend_Db_Select($db);

    // profile page
    $select
      ->from('engine4_core_pages')
      ->where('name = ?', 'user_profile_index')
      ->limit(1);
    $page_id = $select->query()->fetchObject()->page_id;

	$db->query("DELETE FROM `engine4_core_content` WHERE page_id = '$page_id' AND `name` = 'album.profile-albums'");
    // album.profile-albums

    // Check if it's already been placed
    $select = new Zend_Db_Select($db);
    $select
      ->from('engine4_core_content')
      ->where('page_id = ?', $page_id)
      ->where('type = ?', 'widget')
      ->where('name = ?', 'ialbum.profile-albums')
      ;

    $info = $select->query()->fetch();
    
    if( empty($info) ) {
      // container_id (will always be there)
      $select = new Zend_Db_Select($db);
      $select
        ->from('engine4_core_content')
        ->where('page_id = ?', $page_id)
        ->where('type = ?', 'container')
        ->limit(1);
      $container_id = $select->query()->fetchObject()->content_id;

      // middle_id (will always be there)
      $select = new Zend_Db_Select($db);
      $select
        ->from('engine4_core_content')
        ->where('parent_content_id = ?', $container_id)
        ->where('type = ?', 'container')
        ->where('name = ?', 'middle')
        ->limit(1);
      $middle_id = $select->query()->fetchObject()->content_id;
      
      // tab_id (tab container) may not always be there
      $select
        ->reset('where')
        ->where('type = ?', 'widget')
        ->where('name = ?', 'core.container-tabs')
        ->where('page_id = ?', $page_id)
        ->limit(1);
      $tab_id = $select->query()->fetchObject();
      if( $tab_id && @$tab_id->content_id ) {
          $tab_id = $tab_id->content_id;
      } else {
        $tab_id = null;
      }

      // tab on profile
      $db->insert('engine4_core_content', array(
        'page_id' => $page_id,
        'type'    => 'widget',
        'name'    => 'ialbum.profile-albums',
        'parent_content_id' => ($tab_id ? $tab_id : $middle_id),
        'order'   => 4,
        'params'  => '{"title":"Albums","titleCount":true}',
      ));
      
      return $this;
    }
  }
  protected function _albumHomePage()
  {
    
    $db = $this->getDb();

    // profile page
    $page_id = $db->select()
      ->from('engine4_core_pages', 'page_id')
      ->where('name = ?', 'ialbum_index_home')
      ->limit(1)
      ->query()
      ->fetchColumn();

    
    // insert if it doesn't exist yet
    if( !$page_id ) {
      // Insert page
      $db->insert('engine4_core_pages', array(
        'name' => 'ialbum_index_home',
        'displayname' => 'iAlbum - Album Home Page',
        'title' => 'iAlbum - Album Home Page',
        'description' => 'This page show album home page.',
        'custom' => 0,
      ));
      $page_id = $db->lastInsertId();
      
      // Insert top
      $db->insert('engine4_core_content', array(
        'type' => 'container',
        'name' => 'top',
        'page_id' => $page_id,
        'order' => 1,
      ));
      $top_id = $db->lastInsertId();
      
      // Insert main
      $db->insert('engine4_core_content', array(
        'type' => 'container',
        'name' => 'main',
        'page_id' => $page_id,
        'order' => 2,
      ));
      $main_id = $db->lastInsertId();
      
      // Insert top-middle
      $db->insert('engine4_core_content', array(
        'type' => 'container',
        'name' => 'middle',
        'page_id' => $page_id,
        'parent_content_id' => $top_id,
      ));
      $top_middle_id = $db->lastInsertId();
      
      // Insert main-middle
      $db->insert('engine4_core_content', array(
        'type' => 'container',
        'name' => 'middle',
        'page_id' => $page_id,
        'parent_content_id' => $main_id,
        'order' => 3,
      ));
      $main_middle_id = $db->lastInsertId();
      
      // Insert main-right
      $db->insert('engine4_core_content', array(
        'type' => 'container',
        'name' => 'right',
        'page_id' => $page_id,
        'parent_content_id' => $main_id,
        'order' => 2,
      ));
      $main_right_id = $db->lastInsertId();
      
      // Insert main-left
      $db->insert('engine4_core_content', array(
        'type' => 'container',
        'name' => 'left',
        'page_id' => $page_id,
        'parent_content_id' => $main_id,
        'order' => 1,
      ));
      $main_left_id = $db->lastInsertId();
      
      // top
      // Insert menu
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'ialbum.browse-menu',
        'page_id' => $page_id,
        'parent_content_id' => $top_middle_id,
        'order' => 1,
      ));
      
      //main - left
      // Insert ialbum.most-liked-photos
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'ialbum.most-liked-photos',
        'page_id' => $page_id,
        'parent_content_id' => $main_left_id,
        'order' => 1,
        'params' => '{"title":"Most Liked Photos"}',
      ));
      
      // Insert ialbum.friend-photos-tagged
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'ialbum.friend-photos-tagged',
        'page_id' => $page_id,
        'parent_content_id' => $main_left_id,
        'order' => 2,
        'params' => '{"title":"Friends\' Photos Tagged"}',
      ));
      
      // Insert ialbum.friend-photos'
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'ialbum.friend-photos',
        'page_id' => $page_id,
        'parent_content_id' => $main_left_id,
        'order' => 3,
        'params' => '{"title":"Friends\' Photos"}',
      ));
      // Insert ialbum.random-photos
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'ialbum.random-photos',
        'page_id' => $page_id,
        'parent_content_id' => $main_left_id,
        'order' => 4,
        'params' => '{"title":"Random Photos","itemCountPerPage":"5","viewType":"vertical"}',
      ));
      
      //main-middle
      // Insert ialbum.feature-photos
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'ialbum.feature-photos',
        'page_id' => $page_id,
        'parent_content_id' => $main_middle_id,
        'order' => 1,
      ));
      // Insert core.container-tabs - albums
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'core.container-tabs',
        'page_id' => $page_id,
        'parent_content_id' => $main_middle_id,
        'order' => 2,
      	'params' => '{"max":6}'
      ));
      $container_album_id = $db->lastInsertId();
      
      // Insert ialbum.recent-albums
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'ialbum.recent-albums',
        'page_id' => $page_id,
        'parent_content_id' => $container_album_id,
        'order' => 3,
      	'params' => '{"title":"Recent Albums","itemCountPerPage":"12","recentType":"modified_date","nomobile":"0","name":"ialbum.recent-albums"}'
      ));
      // Insert ialbum.most-comment-albums
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'ialbum.most-comment-albums',
        'page_id' => $page_id,
        'parent_content_id' => $container_album_id,
        'order' => 4,
      	'params' => '{"title":"Most Comment Albums","itemCountPerPage":"12","nomobile":"0","name":"ialbum.most-comment-albums"}'
      ));
      // Insert ialbum.most-viewed-albums
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'ialbum.most-viewed-albums',
        'page_id' => $page_id,
        'parent_content_id' => $container_album_id,
        'order' => 5,
      	'params' => '{"title":"Most Viewed Albums","itemCountPerPage":"12"}'
      ));
      
//      // Insert HTML BLOCK
//       $db->insert('engine4_core_content', array(
//        'type' => 'widget',
//        'name' => 'core.html-block',
//        'page_id' => $page_id,
//        'parent_content_id' => $main_middle_id,
//        'order' => 6,
//      	'params' => '{"title":"","data":"<div class=\"clearfix\"><\/div>","nomobile":"0","name":"core.html-block"}'
//      )); 
      
      // Insert core.container-tabs - photos
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'core.container-tabs',
        'page_id' => $page_id,
        'parent_content_id' => $main_middle_id,
        'order' => 7,
      	'params' => '{"max":6}'
      ));
      $container_photo_id = $db->lastInsertId();
      // Insert ialbum.recent-photos
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'ialbum.recent-photos',
        'page_id' => $page_id,
        'parent_content_id' => $container_photo_id,
        'order' => 8,
      	'params' => '{"title":"Recent Photos"}'
      ));
       // Insert ialbum.most-comment-photos
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'ialbum.most-comment-photos',
        'page_id' => $page_id,
        'parent_content_id' => $container_photo_id,
        'order' => 9,
      	'params' => '{"title":"Most Comment Photos"}'
      ));
      // Insert ialbum.most-viewed-photos
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'ialbum.most-viewed-photos',
        'page_id' => $page_id,
        'parent_content_id' => $container_photo_id,
        'order' => 10,
      	'params' => '{"title":"Most Viewed Photos"}'
      ));
      
      ////main-right
      // Insert search
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'ialbum.browse-search',
        'page_id' => $page_id,
        'parent_content_id' => $main_right_id,
        'order' => 1,
      ));
      
      // Insert browse menu
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'album.browse-menu-quick',
        'page_id' => $page_id,
        'parent_content_id' => $main_right_id,
        'order' => 2,
      ));
      // Insert ialbum.album-categories
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'ialbum.album-categories',
        'page_id' => $page_id,
        'parent_content_id' => $main_right_id,
        'order' => 3,
      	'params' => '{"title":"Album Categories"}',
      ));
      // Insert ialbum.top-poster
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'ialbum.top-poster',
        'page_id' => $page_id,
        'parent_content_id' => $main_right_id,
        'order' => 4,
      	'params' => '{"title":"Top Posters"}',
      ));
      // Insert ialbum.most-liked-albums
      $db->insert('engine4_core_content', array(
        'type' => 'widget',
        'name' => 'ialbum.most-liked-albums',
        'page_id' => $page_id,
        'parent_content_id' => $main_right_id,
        'order' => 5,
      	'params' => '{"title":"Most Liked Albums"}',
      ));
    }
    
    return $this;
  }
  public function update(){
  	$db = $this->getDb();
  	$db->query("UPDATE `engine4_core_menuitems` SET `params` = '{\"route\":\"album_general\"}' WHERE `name` = 'core_main_album' LIMIT 1;");
  	$db->query("INSERT IGNORE INTO `engine4_core_menuitems` (`name`, `module`, `label`, `plugin`, `params`, `menu`, `submenu`, `order`) VALUES ('ialbum_admin_main_photo', 'ialbum', 'View Photos', '', '{\"route\":\"admin_default\",\"module\":\"ialbum\",\"controller\":\"manage\", \"action\":\"photo\"}', 'album_admin_main', '', 2)");
  }
}
?>